<template>
  <div>
    <div style="display: flex;justify-content: center;margin-top: 30px">
      <el-card style="width: 80%;margin: 10px">
        <div style="display: flex;border-bottom: 2px solid #8c8c8c">
          <div style="flex: 1;height: 50px;font-size: 25px">用户ID  <span
              style="color: #409EFF">{{ userName }}</span>  的优惠券
          </div>
          <div style="height: 50px;font-size: 25px;flex: 1">
            <el-input style="width: 200px;margin: 0 15px" placeholder="请输入用户账户" v-model="user_name" type="number" min="0" :controls="false"></el-input>
            <el-button type="primary" size="medium" @click="loadCoupon()" style="height: 40px">查询</el-button>
          </div>
        </div>
        <div style="display: flex;align-items: center;justify-content: center;margin-top: 10px">
        </div>
      </el-card>
    </div>
    <div style="display: flex;justify-content: center">
      <el-card style="width: 80%;margin: 10px">
        <div style="height: 50px;font-size: 25px">优惠券</div>
          <div style="margin-bottom: 10px"></div>
          <el-table ref="couponData" :data="couponData" stripe
                    :header-cell-style="{backgroundColor:'aliceblue',color:'#666'}">
            <el-table-column prop="id" label="id"></el-table-column>
            <el-table-column prop="name" label="优惠券名称 "></el-table-column>
            <el-table-column prop="discount" label="优惠券金额 "></el-table-column>
            <el-table-column prop="status" label="状态"></el-table-column>
          </el-table>
          <div style="margin: 10px 0">
            <el-pagination
                @current-change="handleCurrentChange2"
                :current-page="pageNum2"
                :page-sizes="[100, 200, 300, 400]"
                :page-size="pageSize2"
                layout="total,  prev, pager, next"
                :total="total2">
            </el-pagination>
          </div>
      </el-card>
    </div>
  </div>
</template>

<script>
export default {
  name: "userCoupons",
  data() {
    return {
      dialogCoupon: false,
      dialogRecharge: false,
      integral: '',
      RechargeForm: {
        money: "",
      },
      user_id: "",
      tableData: [], //表中数据
      couponData: [],
      pageNum2: 1,   //当前页码
      pageSize2: 5,    //每页数量
      total2: 0,
      balance: 0,
      user_name:"",
      userName:"",
    }
  },
  created() {
    this.loadCoupon();
  },
  methods: {
    handleCurrentChange2(pageNum2) {//下一页
      this.loadCoupon(pageNum2)
    },
    loadCoupon(pageNum2) {
      if (pageNum2) this.pageNum2 = pageNum2
      this.$request.post('/coupon_entity_list/', {
        "username": this.user_name,
        "page_size": this.pageSize2,
        "page_id": this.pageNum2,
      }).then(res => {
        if (res.code === '200') {
          this.couponData = res.data.coupon_list
          this.total2 = res.data.item_amount
          console.log("查询优惠券", res)
          if (res.msg === "查询成功") {
            this.$message.success(res.msg)
            this.userName = this.user_name
          }else {
            this.$message.warning("找不到该用户")
          }
        } else {
            this.$message.error(res.msg)
        }
      })
    },
  }
}
</script>
<style scoped>
  /deep/ input::-webkit-outer-spin-button,
  /deep/ input::-webkit-inner-spin-button {
      -webkit-appearance: none;
  }
  /deep/ input[type="number"] {
      -moz-appearance: textfield;
  }
  /deep/ inpit {
      border: none
  }
</style>